from PyQt5.QtCore import QObject, pyqtSignal, QThread
from robotdriver import robot_driver, my_robot
import time
from blue_tooth import BluetoothDataTransfer

class MyThread1(QThread):
    update_data = pyqtSignal(list)
    def __init__(self):
            super().__init__()
            self.is_running = True

    def run(self):
        self.is_running = True
        while self.is_running:
            self.update_sim_joins_work()
            time.sleep(0.1)
        self.finished.emit()
        
    def stop(self):
        self.is_running = False
        
    def update_sim_joins_work(self):
        joints = robot_driver.get_joints_status()
        self.update_data.emit(joints)
        
target_address = "68:86:08:0A:2A:33"
target_name = "JDY-33-SH"
class MyThread2(QThread):
    update_data = pyqtSignal(list)
    def __init__(self, bd):
        super().__init__()
        self.bd:BluetoothDataTransfer = bd
        self.is_running = True

    def run(self):
        self.is_running = True
        while self.is_running:
            self.update_real_joins_work()
        try:
            self.bd.disconnect()
        except:
            pass
        self.finished.emit()
        
    def stop(self):
        self.is_running = False
        
    def update_real_joins_work(self):
        joints = self.bd.receive_data()
        if joints!=None:
            self.update_data.emit(joints)
            print(joints)